const BASE_URL = "https://next.itxl.club:3000/api";
// const BASE_URL = "http://localhost:3000/api";

export const request = (params) => {
  let header = { ...params.header };
  header["Authorization"] = wx.getStorageSync("token");

  return new Promise((resolve, reject) => {
    wx.request({
      ...params,
      header,
      url: BASE_URL + params.url,
      success: (result) => {
        const status = result.data.status;
        switch (status) {
          case 403:
            wx.showToast({ title: "请先登录", icon: "error" });
            return;
          case 402:
            wx.showToast({ title: "认证失败", icon: "error" });
            return;
          case 401:
            wx.showToast({ title: "请重新登录", icon: "error" });
            return;
        }
        resolve(result.data);
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};
